home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / texmac.zip / SORT.SPM < prev    next >
Text File  |  1991-01-05  |  3KB  |  89 lines

  1. ; Copyright (c) 1988 Borland International.  All Rights Reserved
  2. ;
  3. ; NAME: SORT.SPM
  4. ; VERSION: 1.01
  5. ; DESCRIPTION: Sort macros
  6. ; LAST UPDATE: September 9, 1988
  7. ;
  8. ; NOTES: This file must be compiled and loaded AFTER CORE.SPM.
  9. ; USES EXTERNAL SORT PROGRAM SPSORT.EXE
  10. ;----------------------------------------------
  11. ; Q register usage:
  12. ; see SP.SPM for register and mark tables 
  13.  
  14. ;----------------------------------------------
  15. ;    CONTENTS:
  16. ;    SECTION:  Routines whose definitions are to be removed.
  17. ;    SECTION:    Routines that MUST exist for the compiler to work
  18. ;    SECTION:    Variables -- all the variables are declared here
  19. ;    SECTION:    Forward declarations -- In order to keep the main list
  20. ;            of macros in alphabetical order, a few of them have to be
  21. ;            declared ahead of time -- like a FORWARD declaration
  22. ;            in Pascal
  23. ;    SECTION:    Automatically-called macro definitions (Main, Init,
  24. ;            EditKeys, MacroKeys, etc.)
  25. ;    SECTION:    General and command macros in alphabetical order
  26. ;    SECTION:    Menus (leaves first, root last)
  27. ;    SECTION:    Control and function keys
  28. ;----------------------------------------------
  29. #define RevOrder 0    ; sorting order
  30. #define Was        ; was a block or a column
  31. ; --------------------------------------------------
  32. ; Forward reference for Help
  33. ;--
  34. ; now I have pcsort, might prefer it here instead.
  35. SortHelp:
  36.  
  37. DoSort :
  38.     ; check to see if spsort.exe sorting program is present
  39.     set Q0 "spsort.exe" NeedDisk
  40.     if modf WantSave
  41.     0 QTMP    ; create temp file in home directory in Q0
  42.     ; spsort is present, so do the sort...
  43.         select case {
  44.           1    ;--- write block to external file
  45.             if (current != '^J') tosol        ; Take only entire line
  46.             swapmark
  47.             line->int vline
  48.             swapmark
  49.             if line=vline return    ; Only one line selected
  50.             writeregion togmark Q0
  51. ; need to handle home dir. here
  52.             select -> Was
  53.             RegionErase
  54.             Unselect,
  55.           2    ;--- write Column to external file
  56.             ColSDelete        ; call column macro deletion in QH
  57.             swapmark
  58.             mark    ( to QH write Q0 )
  59.             select->Was
  60.             Unselect
  61.          }
  62.         ;--- now call external sorting program
  63.         status "Sorting..."
  64.         if RevOrder { 32 call "spsort " Q0 " -r" }
  65.         else { 32 call "spsort " Q0 }
  66.         
  67.         if (Was = 1) read Q0
  68.         else { ; write the sorted file in column buffer
  69.             mark (
  70.                 to QH clear
  71.                 if !select $ read Q0
  72.                 )
  73.             ColInsert    ; insert the sorted column at point
  74.             }
  75.         ;--- delete temporary files
  76.         fdelete Q0
  77.  
  78. SortMenu :
  79.     if !select NoBlock
  80.     menu "Sort" (
  81.         "Ascending" SortHelp 0,
  82.         "Descending" SortHelp 1
  83.     )->RevOrder
  84.     abortkey->int OldAbort
  85.     -1->abortkey
  86.     DoSort
  87.     OldAbort->abortkey
  88.  
  89.